/*
 * ObjectGroup.cpp
 *
 *  Created on: Aug 26, 2011
 *      Author: mengwei.chua
 */

#include "ObjectGroup.h"
#include "ParserHelper.h"

namespace projectcos
{
namespace tile
{
namespace parser
{

ObjectGroup::ObjectGroup()
: m_Name("")
{
	m_ObjectList.clear();
}

ObjectGroup::~ObjectGroup()
{
	m_ObjectList.clear();
}

bool ObjectGroup::Parse(const TiXmlElement* element)
{
	if(NULL != element)
	{
		// Parse attribute
		TIXML_QUERY_STRING(element, "name", m_Name);

		// Parse element
		const TiXmlElement* child = element->FirstChildElement("object");
		while(NULL != child)
		{
			Object object;
			if(object.Parse(child))
			{
				m_ObjectList.push_back(object);
			}

			child = child->NextSiblingElement("object");
		}
	}
	else
	{
		return false;
	}

	return true;
}

std::string ObjectGroup::GetName() const
{
	return m_Name;
}

void ObjectGroup::GetObjects(std::deque<Object>& objects) const
{
	objects = m_ObjectList;
}

} // parser
} // tile
} // projectcos
